package Function;

import VWorldGameStudio.events.DoorEvent;
import com.google.gson.Gson;
import jxl.Cell;
import jxl.Sheet;
import jxl.Workbook;
import utils.FCDataSingles;

import java.io.File;
import java.io.FileInputStream;
import java.io.InputStream;

public class BuildFCDoorEventMain {
    private static final String ITEM_FILE = "./material/config/重装机兵V-数据-怪物.xls";
    private Gson gson = new Gson();
    Sheet sheet;

    public static void main(String[] args) {
        BuildFCDoorEventMain main = new BuildFCDoorEventMain();
        main.init();
    }


    private void init(){
        FCEventLibrary fcEventLibrary = new FCEventLibrary();
        fcEventLibrary.loadEventData();

        try {
            File file = new File(ITEM_FILE);
            // 创建输入流，读取Excel
            InputStream is = new FileInputStream(file.getAbsolutePath());
            // jxl提供的Workbook类
            Workbook wb = Workbook.getWorkbook(is);
            sheet = wb.getSheet(7);

            for (int i = 1; i < sheet.getRows(); i++) {
                Cell[] cells = sheet.getRow(i);
                if (cells != null && cells.length > 4) {
                    if (cells[2] == null || cells[2].getContents().isEmpty()) {
                        continue;
                    }
                    String doorEventNam = cells[2].getContents().trim();
                    String keyItem = cells[3].getContents().trim();
                    DoorEvent doorEvent = new DoorEvent("door", doorEventNam);
                    doorEvent.setNeedItemKey(keyItem);
                    FCDataSingles.getWriter().writeEventData(doorEvent);
                }
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}
